package com.scau.XFourPOS.model;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**     
 * 类名称：SaleOrder
 * 类描述：订单表
 * 创建人：庄祥鹏
 * */
@Entity
@Table(name = "sale_order")
public class SaleOrder {
	@Id
	@Column(unique=true,nullable=false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;//key
	
	@Column(name="sale_order_NO",length=50/*,unique=true*/)
	private String saleOrderNO;//唯一，自动按规则生成
	
	@ManyToOne(cascade={CascadeType.MERGE,CascadeType.REFRESH})
	private Customer customer;//外键
	
	@Column(length=50)
	private Double total; 
	
	@Column(length=50)
	private Date createDateTime; 
	
	@Transient
	@ManyToMany(cascade=CascadeType.ALL,targetEntity=Product.class)
	private Set<Product> product=new HashSet<Product>();
	
	public SaleOrder(){
		Random random = new Random();
		this.saleOrderNO="XF"+"-"+String.valueOf((new Date()).getTime())+"-"+random.nextInt(1000);
		this.createDateTime=new Date();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getSaleOrderNO() {
		return saleOrderNO;
	}

	public void setSaleOrderNO(String saleOrderNO) {
		this.saleOrderNO = saleOrderNO;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Double getTotal() {
		return total;
	}

	public void setTotal(Double total) {
		this.total = total;
	}

	public Date getCreateDateTime() {
		return createDateTime;
	}

	public void setCreateDateTime(Date createDateTime) {
		this.createDateTime = createDateTime;
	}

	public Set<Product> getProduct() {
		return product;
	}

	public void setProduct(Set<Product> product) {
		this.product = product;
	}
	
}
